namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;

    public abstract class CellAlignment : InnerElements, IXmlSerializable
    {
        public string Alignment
        {
            get;
            set;
        }

        public string Character
        {
            get;
            set;
        }

        public string CharacterOffset
        {
            get;
            set;
        }

        public string VerticalAlignment
        {
            get;
            set;
        }

        public override void ReadXml(XmlReader reader)
        {
            string value = reader.GetAttribute("align");
            if (!string.IsNullOrEmpty(value))
            {
                this.Alignment = value;
            }

            value = reader.GetAttribute("char");
            if (!string.IsNullOrEmpty(value))
            {
                this.Character = value;
            }

            value = reader.GetAttribute("charoff");
            if (!string.IsNullOrEmpty(value))
            {
                this.CharacterOffset = value;
            }

            value = reader.GetAttribute("valign");
            if (!string.IsNullOrEmpty(value))
            {
                this.VerticalAlignment = value;
            }

            base.ReadXml(reader);
        }

        public override void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Alignment))
            {
                writer.WriteAttributeString("align", this.Alignment);
            }

            if (!string.IsNullOrEmpty(this.Character))
            {
                writer.WriteAttributeString("char", this.Character[0].ToString());
            }

            if (!string.IsNullOrEmpty(this.CharacterOffset))
            {
                writer.WriteAttributeString("charoff", this.CharacterOffset);
            }

            if (!string.IsNullOrEmpty(this.VerticalAlignment))
            {
                writer.WriteAttributeString("valign", this.VerticalAlignment);
            }

            base.WriteXml(writer);
        }
    }
}